#pragma once
#include <Poco/Runnable.h>
#include <Poco/ThreadPool.h>

#include <iostream>

#include "MyFmt.h"

// 2. 定义任务类（继承自 Poco::Runnable）
class MyTask : public Poco::Runnable
{
public:
    /// Do whatever the thread needs to do. Must be overridden by subclasses.
    void run() override { INFO("Task executed by thread: {}", Poco::Thread::current()->name()); }
};

// 3. 创建线程池并提交任务
FnInInt Te_thread_pool()
{
    // 创建线程池：最少2个线程，最多8个线程，空闲60秒后回收
    Poco::ThreadPool pool("MyPool", 2, 8, 60);

    /// Obtains a thread and starts the target.
    /// Throws a NoThreadAvailableException if no more threads are available.
    for (int i = 0; i < 10; ++i)
    {
        pool.start(*new MyTask());  // 注意：Poco不管理Runnable生命周期
    }

    pool.joinAll();  // 等待所有任务完成; 阻塞调用

    INFOC("All threads end");

    return 0;
}